Typed Config Access
authorEric Huss <eric@huss.org>
Tue, 15 May 2018 04:57:47 +0000 (21:57 -0700)
committerEric Huss <eric@huss.org>
Sat, 19 May 2018 18:05:03 +0000 (11:05 -0700)
commitd64122454b3cbd84b412b442a45d6d04524ba8a5
treec12370b96d3a804a173b72790acd2985f641634f
parent64f8f1b72f6afaa2fcc01e30537e3efdb1d651f2
Typed Config Access

This introduces a new API for accessing config values using serde to
automatically convert to a destination type.  By itself this shouldn't
introduce any behavioral changes (except for some slight wording changes to
error messages).  However, it unlocks the ability to use richer data types in
the future (such as `profile`, or `source`).  Example:

```rust
let p: Option<TomlProfile> = config.get("profile.dev")?;
```

Supports environment variables when fetching structs or maps.  Note that it can
support underscores in env var for struct field names, but not maps.  So for
example, "opt_level" works, but not "serde_json" (example:
`CARGO_PROFILE_DEV_OVERRIDES_serde_OPT_LEVEL`).  I don't have any ideas for a
workaround (though I feel this is an overuse of env vars).

It supports environment variables for lists.  The value in the env var will get
appended to anything in the config.  It uses TOML syntax, and currently only
supports strings.  Example:  `CARGO_FOO=['a', 'b']`.  I did *not* modify
`get_list` to avoid changing behavior, but that can easily be changed.
src/cargo/core/compiler/build_config.rs
src/cargo/lib.rs
src/cargo/util/config.rs
src/cargo/util/toml/mod.rs
tests/testsuite/bad_config.rs
tests/testsuite/config.rs